//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    bannerList:[],
    hotList:[],
    lastestList:[],
    network:getApp().globalData["network"]
  },
  todtl:function(event){
    var index =event.currentTarget.dataset.index;
    console.log(index);
    wx.navigateTo({
      url:"/pages/detail/detail",
      events:{
        // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
        acceptDataFromOpenedPage: function(data) {
         // console.log(data)
        },
      },
      success: function(res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage',index)
      }
    });
  },
  onLoad: function () {
    var that = this;
    console.log("onload");
    // 广告
    wx.request({
      url:"http://"+that.data.network+"/front/bannerQueryAll.php",
      method:"post",
      datatype:"json",
      success:function(data){
        that.setData({
          bannerList:data.data

        });
        console.log(that.data.bannerList);
      }
    });
    //热门推荐
    wx.request({
      url: "http://" + that.data.network +"/front/hotrecommand.php",
      method:"post",
      datatype:"json",
      success:function(data){
        that.setData({
          hotList:data.data

        });
        console.log(that.data.hotList);
        
      }
    });
    //最新发布
    wx.request({
      url: "http://" + that.data.network +"/front/lastestPub.php",
      method:"post",
      datatype:"json",
      success:function(data){
        that.setData({
          lastestList:data.data

        });
        console.log(that.data.lastestList);
        
      }
    });
  },
})
